/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.user.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.user.dto.AppFuelReceivePageDTO;
import com.pig4cloud.pigx.user.dto.FuelReceiveDividendsPageDTO;
import com.pig4cloud.pigx.user.entity.FuelReceiveDividends;
import com.pig4cloud.pigx.user.service.FuelReceiveDividendsService;
import com.pig4cloud.pigx.user.vo.AdminPageDemoVO;
import com.pig4cloud.pigx.user.vo.LoginUserFuelReceiveVO;
import com.pig4cloud.pigx.user.vo.MarginBalanceVO;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 燃料分红明细
 *
 * @author pigx code generator
 * @date 2022-11-24 17:38:53
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fuel_receive_dividends" )
@Api(value = "fuelreceivedividends", tags = "燃料分红明细管理")
public class FuelReceiveDividendsController {

    private final  FuelReceiveDividendsService fuelReceiveDividendsService;

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page" )
    public R<AdminPageDemoVO<FuelReceiveDividends>> getFuelReceiveDividendsPage(@RequestBody FuelReceiveDividendsPageDTO dto) {
        return fuelReceiveDividendsService.pageList(dto);
    }

	/**
	 * 获取用户燃料分红明细 分页
	 * @param dto dto
	 * @return r
	 */
	@PostMapping("/app/page")
	public R<Page<LoginUserFuelReceiveVO>> getAppPage(@RequestBody AppFuelReceivePageDTO dto) {
		return fuelReceiveDividendsService.getAppPage(dto);
	}

	/**
	 * 获取平台保险金额度
	 * @return r
	 */
	@GetMapping("/margin")
	public R<MarginBalanceVO> getMarginBalance() {
		return fuelReceiveDividendsService.getMarginBalance();
	}


    /**
     * 通过id查询燃料分红明细
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('user_fuelreceivedividends_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(fuelReceiveDividendsService.getById(id));
    }

    /**
     * 新增燃料分红明细
     * @param fuelReceiveDividends 燃料分红明细
     * @return R
     */
    @ApiOperation(value = "新增燃料分红明细", notes = "新增燃料分红明细")
    @SysLog("新增燃料分红明细" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user_fuelreceivedividends_add')" )
    public R save(@RequestBody FuelReceiveDividends fuelReceiveDividends) {
        return R.ok(fuelReceiveDividendsService.save(fuelReceiveDividends));
    }

    /**
     * 修改燃料分红明细
     * @param fuelReceiveDividends 燃料分红明细
     * @return R
     */
    @ApiOperation(value = "修改燃料分红明细", notes = "修改燃料分红明细")
    @SysLog("修改燃料分红明细" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user_fuelreceivedividends_edit')" )
    public R updateById(@RequestBody FuelReceiveDividends fuelReceiveDividends) {
        return R.ok(fuelReceiveDividendsService.updateById(fuelReceiveDividends));
    }

    /**
     * 通过id删除燃料分红明细
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除燃料分红明细", notes = "通过id删除燃料分红明细")
    @SysLog("通过id删除燃料分红明细" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('user_fuelreceivedividends_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(fuelReceiveDividendsService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param fuelReceiveDividends 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('user_fuelreceivedividends_export')" )
    public List<FuelReceiveDividends> export(FuelReceiveDividends fuelReceiveDividends) {
        return fuelReceiveDividendsService.list(Wrappers.query(fuelReceiveDividends));
    }
}
